home *** CD-ROM | disk | FTP | other *** search
/ Enter Special 5: Digital Photography / ENTER Special 05.iso / Grafika / Paint Shop Pro 8.0 / psp800ev.exe / Data1.cab / string.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-22  |  13.3 KB  |  376 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. """A collection of string operations (most are no longer used in Python 1.6).
  5.  
  6. Warning: most of the code you see here isn't normally used nowadays.  With
  7. Python 1.6, many of these functions are implemented as methods on the
  8. standard string object. They used to be implemented by a built-in module
  9. called strop, but strop is now obsolete itself.
  10.  
  11. Public module variables:
  12.  
  13. whitespace -- a string containing all characters considered whitespace
  14. lowercase -- a string containing all characters considered lowercase letters
  15. uppercase -- a string containing all characters considered uppercase letters
  16. letters -- a string containing all characters considered letters
  17. digits -- a string containing all characters considered decimal digits
  18. hexdigits -- a string containing all characters considered hexadecimal digits
  19. octdigits -- a string containing all characters considered octal digits
  20. punctuation -- a string containing all characters considered punctuation
  21. printable -- a string containing all characters considered printable
  22.  
  23. """
  24. whitespace = ' \t\n\r\x0b\x0c'
  25. lowercase = 'abcdefghijklmnopqrstuvwxyz'
  26. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  27. letters = lowercase + uppercase
  28. ascii_lowercase = lowercase
  29. ascii_uppercase = uppercase
  30. ascii_letters = ascii_lowercase + ascii_uppercase
  31. digits = '0123456789'
  32. hexdigits = digits + 'abcdef' + 'ABCDEF'
  33. octdigits = '01234567'
  34. punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
  35. printable = digits + letters + punctuation + whitespace
  36. _idmap = ''
  37. for i in range(256):
  38.     _idmap = _idmap + chr(i)
  39.  
  40. del i
  41. index_error = ValueError
  42. atoi_error = ValueError
  43. atof_error = ValueError
  44. atol_error = ValueError
  45.  
  46. def lower(s):
  47.     '''lower(s) -> string
  48.  
  49.     Return a copy of the string s converted to lowercase.
  50.  
  51.     '''
  52.     return s.lower()
  53.  
  54.  
  55. def upper(s):
  56.     '''upper(s) -> string
  57.  
  58.     Return a copy of the string s converted to uppercase.
  59.  
  60.     '''
  61.     return s.upper()
  62.  
  63.  
  64. def swapcase(s):
  65.     '''swapcase(s) -> string
  66.  
  67.     Return a copy of the string s with upper case characters
  68.     converted to lowercase and vice versa.
  69.  
  70.     '''
  71.     return s.swapcase()
  72.  
  73.  
  74. def strip(s):
  75.     '''strip(s) -> string
  76.  
  77.     Return a copy of the string s with leading and trailing
  78.     whitespace removed.
  79.  
  80.     '''
  81.     return s.strip()
  82.  
  83.  
  84. def lstrip(s):
  85.     '''lstrip(s) -> string
  86.  
  87.     Return a copy of the string s with leading whitespace removed.
  88.  
  89.     '''
  90.     return s.lstrip()
  91.  
  92.  
  93. def rstrip(s):
  94.     '''rstrip(s) -> string
  95.  
  96.     Return a copy of the string s with trailing whitespace
  97.     removed.
  98.  
  99.     '''
  100.     return s.rstrip()
  101.  
  102.  
  103. def split(s, sep = None, maxsplit = -1):
  104.     '''split(s [,sep [,maxsplit]]) -> list of strings
  105.  
  106.     Return a list of the words in the string s, using sep as the
  107.     delimiter string.  If maxsplit is given, splits into at most
  108.     maxsplit words.  If sep is not specified, any whitespace string
  109.     is a separator.
  110.  
  111.     (split and splitfields are synonymous)
  112.  
  113.     '''
  114.     return s.split(sep, maxsplit)
  115.  
  116. splitfields = split
  117.  
  118. def join(words, sep = ' '):
  119.     '''join(list [,sep]) -> string
  120.  
  121.     Return a string composed of the words in list, with
  122.     intervening occurrences of sep.  The default separator is a
  123.     single space.
  124.  
  125.     (joinfields and join are synonymous)
  126.  
  127.     '''
  128.     return sep.join(words)
  129.  
  130. joinfields = join
  131.  
  132. def index(s, *args):
  133.     '''index(s, sub [,start [,end]]) -> int
  134.  
  135.     Like find but raises ValueError when the substring is not found.
  136.  
  137.     '''
  138.     return s.index(*args)
  139.  
  140.  
  141. def rindex(s, *args):
  142.     '''rindex(s, sub [,start [,end]]) -> int
  143.  
  144.     Like rfind but raises ValueError when the substring is not found.
  145.  
  146.     '''
  147.     return s.rindex(*args)
  148.  
  149.  
  150. def count(s, *args):
  151.     '''count(s, sub[, start[,end]]) -> int
  152.  
  153.     Return the number of occurrences of substring sub in string
  154.     s[start:end].  Optional arguments start and end are
  155.     interpreted as in slice notation.
  156.  
  157.     '''
  158.     return s.count(*args)
  159.  
  160.  
  161. def find(s, *args):
  162.     '''find(s, sub [,start [,end]]) -> in
  163.  
  164.     Return the lowest index in s where substring sub is found,
  165.     such that sub is contained within s[start,end].  Optional
  166.     arguments start and end are interpreted as in slice notation.
  167.  
  168.     Return -1 on failure.
  169.  
  170.     '''
  171.     return s.find(*args)
  172.  
  173.  
  174. def rfind(s, *args):
  175.     '''rfind(s, sub [,start [,end]]) -> int
  176.  
  177.     Return the highest index in s where substring sub is found,
  178.     such that sub is contained within s[start,end].  Optional
  179.     arguments start and end are interpreted as in slice notation.
  180.  
  181.     Return -1 on failure.
  182.  
  183.     '''
  184.     return s.rfind(*args)
  185.  
  186. _float = float
  187. _int = int
  188. _long = long
  189. _StringType = type('')
  190.  
  191. def atof(s):
  192.     '''atof(s) -> float
  193.  
  194.     Return the floating point number represented by the string s.
  195.  
  196.     '''
  197.     return _float(s)
  198.  
  199.  
  200. def atoi(s, base = 10):
  201.     '''atoi(s [,base]) -> int
  202.  
  203.     Return the integer represented by the string s in the given
  204.     base, which defaults to 10.  The string s must consist of one
  205.     or more digits, possibly preceded by a sign.  If base is 0, it
  206.     is chosen from the leading characters of s, 0 for octal, 0x or
  207.     0X for hexadecimal.  If base is 16, a preceding 0x or 0X is
  208.     accepted.
  209.  
  210.     '''
  211.     return _int(s, base)
  212.  
  213.  
  214. def atol(s, base = 10):
  215.     '''atol(s [,base]) -> long
  216.  
  217.     Return the long integer represented by the string s in the
  218.     given base, which defaults to 10.  The string s must consist
  219.     of one or more digits, possibly preceded by a sign.  If base
  220.     is 0, it is chosen from the leading characters of s, 0 for
  221.     octal, 0x or 0X for hexadecimal.  If base is 16, a preceding
  222.     0x or 0X is accepted.  A trailing L or l is not accepted,
  223.     unless base is 0.
  224.  
  225.     '''
  226.     return _long(s, base)
  227.  
  228.  
  229. def ljust(s, width):
  230.     '''ljust(s, width) -> string
  231.  
  232.     Return a left-justified version of s, in a field of the
  233.     specified width, padded with spaces as needed.  The string is
  234.     never truncated.
  235.  
  236.     '''
  237.     return s.ljust(width)
  238.  
  239.  
  240. def rjust(s, width):
  241.     '''rjust(s, width) -> string
  242.  
  243.     Return a right-justified version of s, in a field of the
  244.     specified width, padded with spaces as needed.  The string is
  245.     never truncated.
  246.  
  247.     '''
  248.     return s.rjust(width)
  249.  
  250.  
  251. def center(s, width):
  252.     '''center(s, width) -> string
  253.  
  254.     Return a center version of s, in a field of the specified
  255.     width. padded with spaces as needed.  The string is never
  256.     truncated.
  257.  
  258.     '''
  259.     return s.center(width)
  260.  
  261.  
  262. def zfill(x, width):
  263.     '''zfill(x, width) -> string
  264.  
  265.     Pad a numeric string x with zeros on the left, to fill a field
  266.     of the specified width.  The string x is never truncated.
  267.  
  268.     '''
  269.     if type(x) == type(''):
  270.         s = x
  271.     else:
  272.         s = `x`
  273.     n = len(s)
  274.     if n >= width:
  275.         return s
  276.     
  277.     sign = ''
  278.     if s[0] in ('-', '+'):
  279.         (sign, s) = (s[0], s[1:])
  280.     
  281.     return sign + '0' * (width - n) + s
  282.  
  283.  
  284. def expandtabs(s, tabsize = 8):
  285.     '''expandtabs(s [,tabsize]) -> string
  286.  
  287.     Return a copy of the string s with all tab characters replaced
  288.     by the appropriate number of spaces, depending on the current
  289.     column, and the tabsize (default 8).
  290.  
  291.     '''
  292.     return s.expandtabs(tabsize)
  293.  
  294.  
  295. def translate(s, table, deletions = ''):
  296.     '''translate(s,table [,deletions]) -> string
  297.  
  298.     Return a copy of the string s, where all characters occurring
  299.     in the optional argument deletions are removed, and the
  300.     remaining characters have been mapped through the given
  301.     translation table, which must be a string of length 256.  The
  302.     deletions argument is not allowed for Unicode strings.
  303.  
  304.     '''
  305.     if deletions:
  306.         return s.translate(table, deletions)
  307.     else:
  308.         return s.translate(table + s[:0])
  309.  
  310.  
  311. def capitalize(s):
  312.     '''capitalize(s) -> string
  313.  
  314.     Return a copy of the string s with only its first character
  315.     capitalized.
  316.  
  317.     '''
  318.     return s.capitalize()
  319.  
  320.  
  321. def capwords(s, sep = None):
  322.     '''capwords(s, [sep]) -> string
  323.  
  324.     Split the argument into words using split, capitalize each
  325.     word using capitalize, and join the capitalized words using
  326.     join. Note that this replaces runs of whitespace characters by
  327.     a single space.
  328.  
  329.     '''
  330.     if not sep:
  331.         pass
  332.     return join(map(capitalize, s.split(sep)), ' ')
  333.  
  334. _idmapL = None
  335.  
  336. def maketrans(fromstr, tostr):
  337.     '''maketrans(frm, to) -> string
  338.  
  339.     Return a translation table (a string of 256 bytes long)
  340.     suitable for use in string.translate.  The strings frm and to
  341.     must be of the same length.
  342.  
  343.     '''
  344.     global _idmapL
  345.     if len(fromstr) != len(tostr):
  346.         raise ValueError, 'maketrans arguments must have same length'
  347.     
  348.     if not _idmapL:
  349.         _idmapL = map(None, _idmap)
  350.     
  351.     L = _idmapL[:]
  352.     fromstr = map(ord, fromstr)
  353.     for i in range(len(fromstr)):
  354.         L[fromstr[i]] = tostr[i]
  355.     
  356.     return join(L, '')
  357.  
  358.  
  359. def replace(s, old, new, maxsplit = -1):
  360.     '''replace (str, old, new[, maxsplit]) -> string
  361.  
  362.     Return a copy of string str with all occurrences of substring
  363.     old replaced by new. If the optional argument maxsplit is
  364.     given, only the first maxsplit occurrences are replaced.
  365.  
  366.     '''
  367.     return s.replace(old, new, maxsplit)
  368.  
  369.  
  370. try:
  371.     from strop import maketrans, lowercase, uppercase, whitespace
  372.     letters = lowercase + uppercase
  373. except ImportError:
  374.     pass
  375.  
  376.